package com.yizn.learn.reflection;


import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 * 个人类
 *
 * @author yisl
 * @create 2019-06-06 18:01
 */
public class Persion {

    private int age;

    private String name;

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Persion(){
        this.age = 10;
        this.name = "hah";
    }

    public Persion(String name, int age){
        this.name = name;
        this.age = age;
    }


    public static void main(String[] args) throws Exception{

        Class ps1 = Persion.class;

        Persion p = new Persion();
        Class ps2 = p.getClass();

        Class ps3 = Class.forName("com.yizn.learn.reflection.Persion");

        Method[] methods = ps3.getDeclaredMethods();
        for (Method m:methods){
            System.out.println(m.toString());
        }

        Field[] fields = ps3.getDeclaredFields();
        for (Field field:fields){
            System.out.println(field.toString());
        }

        Constructor[] constructors = ps3.getDeclaredConstructors();
        for (Constructor constructor:constructors){
            System.out.println(constructor.toString());
        }



        Persion persion = (Persion) ps3.newInstance();

        Constructor constructor = ps3.getDeclaredConstructor(String.class,int.class);
        Persion persion1 = (Persion) constructor.newInstance("lisi", 24);

        System.out.println(persion.getAge());
        System.out.println(persion1.getAge());

    }
}
